import request, { RequestReturnType } from '/@/utils/request'

export const createOrUpdateMenu = (data:any): RequestReturnType => {
  return request({
    method: 'POST',
    url: '/boss/menu/saveOrUpdate',
    data: data
  })
}

export const getEditMenuInfo = (id = -1): RequestReturnType => {
  return request({
    method: 'GET',
    url: '/boss/menu/getEditMenuInfo',
    params: { id }
  })
}

export const getMenuInfo = (id: number): RequestReturnType => {
  return request({
    method: 'GET',
    url: `/boss/menu/${id}`
  })
}

export const getMenusAll = (): RequestReturnType => {
  return request({
    method: 'GET',
    url: '/boss/menu/getAll'
  })
}
// 删除菜单
export const deleteMenu = (id:number): RequestReturnType => {
  return request({
    method: 'DELETE',
    url: `/boss/menu/${id}`
  })
}

export const getMenuNodeList = ():RequestReturnType => {
  return request({
    method: 'GET',
    url: '/boss/menu/getMenuNodeList'
  })
}

export const allocateRoleMenus = (data: any):RequestReturnType => {
  return request({
    method: 'POST',
    url: '/boss/menu/allocateRoleMenus',
    data
  })
}

export const getRoleMenus = (roleId: string | number):RequestReturnType => {
  return request({
    method: 'GET',
    url: '/boss/menu/getRoleMenus',
    params: { // axios 会把 params 转换为 key=value&key=value 的数据格式放到 url 后面(以?分割)
      roleId
    }
  })
}
